import json
import time
import 贪心算法alg

def run_tests(test_file="test_cases.json"):
    # 加载测试用例
    with open(test_file) as f:
        test_cases = json.load(f)
    
    passed = 0
    failed = []
    
    # 执行所有测试用例
    for i, case in enumerate(test_cases):
        nums = case["nums"]
        expected = case["expected"]
        
        start_time = time.perf_counter()
        result = 贪心算法alg.pivotIndex(nums)
        elapsed = time.perf_counter() - start_time
        
        # 验证结果
        if result == expected:
            passed += 1
            status = "PASS"
        else:
            failed.append(i + 1)
            status = "FAIL"
        
        # 显示测试结果
        print(f"Test {i+1}: {status} | "
              f"Input: {nums[:5]}{'...' if len(nums)>5 else ''} | "
              f"Expected: {expected} | "
              f"Got: {result} | "
              f"Time: {elapsed:.6f}s")
    
    # 输出统计摘要
    print("\n=== TEST SUMMARY ===")
    print(f"Total: {len(test_cases)} | Passed: {passed} | Failed: {len(failed)}")
    if failed:
        print(f"Failed cases: {failed}")
    
    # 单独显示性能测试结果
    perf_case = test_cases[-1]
    if len(perf_case["nums"]) > 100:
        perf_result = 贪心算法alg.pivotIndex(perf_case["nums"])
        print(f"\nPerformance test ({len(perf_case['nums'])} elements):")
        print(f"Expected: {perf_case['expected']} | Got: {perf_result} | {'PASS' if perf_result == perf_case['expected'] else 'FAIL'}")

if __name__ == "__main__":
    run_tests()